package com.azure.code.list;

/**
 * 删除排序链表中的重复元素
 */
public class DeleteDuplicates_83 {

    public ListNode deleteDuplicate(ListNode head) {
        if (head == null) {
            return head;
        }
        ListNode cur = head;
        while (null != cur.next) {
            if (cur.next.val == cur.val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }
        return head;
    }
    /**递归处理，在本质上其实就是将链表压栈后倒叙处理*/
    public ListNode deleteDuplicate2(ListNode head) {
        if (head == null || head.next == null) return head;
        head.next = deleteDuplicate2(head.next);
        return head.val == head.next.val ? head.next : head;
    }
}
